package io.aicn.lowcode.entity.dbmanager;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 表字段信息实体类
 * 
 * @author lowcode-generator
 * @since 2025-01-25
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("dbm_table_column")
public class TableColumn {

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 数据表ID
     */
    @TableField("table_id")
    private Long tableId;

    /**
     * 字段名
     */
    @TableField("column_name")
    private String columnName;

    /**
     * 字段类型
     */
    @TableField("column_type")
    private String columnType;

    /**
     * 字段长度
     */
    @TableField("column_length")
    private Integer columnLength;

    /**
     * 小数位数
     */
    @TableField("decimal_places")
    private Integer decimalPlaces;

    /**
     * 是否允许为空
     */
    @TableField("is_nullable")
    private Boolean isNullable;

    /**
     * 是否主键
     */
    @TableField("is_primary_key")
    private Boolean isPrimaryKey;

    /**
     * 是否自增
     */
    @TableField("is_auto_increment")
    private Boolean isAutoIncrement;

    /**
     * 默认值
     */
    @TableField("default_value")
    private String defaultValue;

    /**
     * 字段注释
     */
    @TableField("column_comment")
    private String columnComment;

    /**
     * 字段位置
     */
    @TableField("ordinal_position")
    private Integer ordinalPosition;

    /**
     * 数据域ID
     */
    @TableField("domain_id")
    private Long domainId;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    /**
     * 创建人
     */
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 常用数据类型枚举
     */
    public enum DataType {
        VARCHAR("VARCHAR", "可变长字符串"),
        CHAR("CHAR", "定长字符串"),
        TEXT("TEXT", "长文本"),
        INT("INT", "整数"),
        BIGINT("BIGINT", "长整数"),
        DECIMAL("DECIMAL", "精确小数"),
        DOUBLE("DOUBLE", "双精度浮点数"),
        DATETIME("DATETIME", "日期时间"),
        DATE("DATE", "日期"),
        TIME("TIME", "时间"),
        TIMESTAMP("TIMESTAMP", "时间戳"),
        BOOLEAN("BOOLEAN", "布尔值"),
        JSON("JSON", "JSON数据");

        private final String code;
        private final String description;

        DataType(String code, String description) {
            this.code = code;
            this.description = description;
        }

        public String getCode() {
            return code;
        }

        public String getDescription() {
            return description;
        }
    }
}